package com.lou;

import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author xgluo
 * @program: makePackage
 * @name: ReadPath
 * @description: 读取  需要打包的文件路径   的文件
 * @date 2025年02月26日
 */
public class Patch {

    public static void main(String[] args) {
//        SelectPathFile selectPathFile = new SelectPathFile();
//        /*url = fileTest.open();*/
//        String url = selectPathFile.openFileDialog();
//        if (url == null ||"".endsWith(url)) {
//            return;
//        }
        String filePath = "D:/patch/patch.txt";
        ReadConfigFile instance = ReadConfigFile.getInstance("propertiesPath");
        System.out.println("projectPath: "+instance.getProjectPath());
        System.out.println("classPath: "+instance.getClassPath());
        System.out.println("webcontextPath: "+instance.getWebcontextPath());
        System.out.println("----------------------------------------");
        /*url = fileTest.open();*/
//        url = selectPathFile.openDialog();
//        if (url == null ||"".endsWith(url)) {
//            return;
//        }
        File selectFile = new File(filePath);
        if(selectFile.isDirectory()) {
            Set<String> uniqueTextFiles = new HashSet<>();
            String[] textFileUrls = selectFile.list((dir, name) -> name.endsWith(".txt"));
            if(textFileUrls != null) {
                // 使用 Stream 去重并遍历
//                Arrays.stream(textFileUrls)
//                        .distinct()
//                        .forEach(this::readPathFile);
                // 将所有文件名添加到 Set 中自动去重
                Collections.addAll(uniqueTextFiles, textFileUrls);
                for (String textFileUrl : uniqueTextFiles) {
                    readPathFile(textFileUrl);
                }
            }
        }else{
            readPathFile(filePath);
        }

        //String projectPath = System.getProperty("user.dir");
        //System.out.println(projectPath);
        System.out.println("文件读取完成！");

    }


    /**
     * @description: 按行读取文件内容，获取需要上线的文件路径
     * @param path 待处理的路径文件
     * @date 2025/2/26
     * @author xgluo
     */
    private static void readPathFile(String path) {
        // 创建对象用于处理文件
        CopyFilesPHP copyFiles = new CopyFilesPHP();
        copyFiles.copyFiles(path);

    }


}
